<template>
    <div class="main-con operationRecord">
        <!-- 搜索框 -->
        <div class="search-con">
            <div class="search-item">
                <div class="search-item-title">操作人</div>
                <div class="search-item-input">
                    <el-input size="mini" v-model="formData.userName" placeholder="请输入操作人" @change="handleSearch"></el-input>
                </div>
            </div>
            <div class="search-item">
                <div class="search-item-title">来源</div>
                <div class="search-item-input">
                    <el-select size="mini" v-model="formData.sources" placeholder="请选择来源">
                        <el-option v-for="item in sourcesOptions" :key="item.value" :label="item.label" :value="item.value">
                        </el-option>
                    </el-select>
                </div>
            </div>
            <div class="search-item">
                <div class="search-item-title">操作模块</div>
                <div class="search-item-input">
                    <el-select size="mini" v-model="formData.moudleCode" placeholder="请选择操作模块">
                        <el-option v-for="item in moudleCodeOptions" :key="item.value" :label="item.label" :value="item.value">
                        </el-option>
                    </el-select>
                </div>
            </div>
            <div class="search-item">
                <div class="search-item-title">操作内容</div>
                <div class="search-item-input">
                    <el-input size="mini" v-model="formData.remark" placeholder="请输入操作内容" @change="handleSearch"></el-input>
                </div>
            </div>
            <div class="search-item">
                <div class="search-item-title">操作门店</div>
                <div class="search-item-input">
                    <el-input size="mini" v-model="formData.storeName" placeholder="请输入操作门店" @change="handleSearch"></el-input>
                </div>
            </div>
            <div class="search-item">
                <div class="search-item-title">操作时间</div>
                <div class="search-item-input">
                    <el-date-picker size="mini" :editable="false" class="w200" v-model="formData.start" type="datetime"
                        placeholder="请选择开始时间" value-format="yyyy-MM-dd HH:mm:ss" :clearable="false"></el-date-picker>
                </div>
                <div>~</div>
                <div class="search-item-input">
                    <el-date-picker size="mini" :editable="false" class="w200" v-model="formData.end" type="datetime"
                        placeholder="请选择结束时间" value-format="yyyy-MM-dd HH:mm:ss" :clearable="false"></el-date-picker>
                </div>
            </div>
            <div class="search-item">
                <div class="search-item-title"></div>
                <el-button size="mini" type="primary" icon="el-icon-search" @click="handleSearch">查询</el-button>
                <el-button size="mini" type="primary" icon="el-icon-delete" @click="handleClear">清空</el-button>
            </div>
        </div>

        <!-- 按钮组 -->
        <div class="btn-group-con">
            <el-button size="mini" type="primary" @click="handleExport">导出</el-button>
        </div>

        <!-- 表格数据 -->
        <div class="table-con" v-loading="loading">
            <el-table :data="tableData" size="mini" :header-cell-style="{background:'#f8f8f8'}" style="width: 100%">
                <el-table-column type="index" label="序号" width="50" align="center" :show-overflow-tooltip="true">
                </el-table-column>
                <el-table-column prop="userName" label="操作人" width="120" align="center" :show-overflow-tooltip="true">
                </el-table-column>
                <el-table-column prop="storeName" label="操作门店" width="120" align="center" :show-overflow-tooltip="true">
                </el-table-column>
                <el-table-column prop="sourcesName" label="操作来源" width="120" align="center" :show-overflow-tooltip="true">
                </el-table-column>
                <el-table-column prop="moudleName" label="操作模块" width="120" align="center" :show-overflow-tooltip="true">
                </el-table-column>
                <el-table-column prop="time" label="操作时间" width="160" align="center" :show-overflow-tooltip="true">
                </el-table-column>
                <el-table-column prop="remark" label="操作内容" width="" align="center" :show-overflow-tooltip="true">
                </el-table-column>
            </el-table>
        </div>

        <!-- 表格分页 -->
        <div class="pagination-con">
            <m-pagination :currentPage="formData.pageNum" :pageSize="formData.pageSize" :total="total"
                @handleCurrentChange="handleCurrentChange" @handleSizeChange="handleSizeChange">
            </m-pagination>
        </div>
    </div>
</template>

<script>
import { queryOperationRecordInfo } from "@/common/service/systemManagement/operationRecord.js";
import mPagination from "@/components/m-pagination/m-pagination";
import { api } from "@/common/http/index.js";
export default {
    name: "operationRecord",
    data() {
        return {
            // 搜索条件
            formData: {
                userName: "", //操作人
                sources: "", //来源
                moudleCode: "", //操作模块
                remark: "", //操作内容
                storeName: "", //操作门店
                start: "", //操作开始时间
                end: "", //操作结束时间
                pageNum: 1,
                pageSize: 10
            },
            sourcesOptions: [
                {
                    value: "1",
                    label: "中台"
                },
                {
                    value: "2",
                    label: "app"
                }
            ], //来源下拉框数据
            moudleCodeOptions: [
                {
                    value: "1",
                    label: "门店管理"
                },
                {
                    value: "2",
                    label: "到货确认"
                },
                {
                    value: "3",
                    label: "商品管理"
                },
                {
                    value: "4",
                    label: "门店员工"
                },
                {
                    value: "5",
                    label: "骑手信息"
                },
                {
                    value: "6",
                    label: "个人设置"
                },
                {
                    value: "7",
                    label: "系统用户"
                },
                {
                    value: "8",
                    label: "订单管理"
                }
            ], //操作模块下拉框数据
            //表格数据
            tableData: [], //表格信息
            total: null, //表格总条数
            loading: false //表格加载动画
        };
    },
    created() {
        //初始化操作时间
        this.getTodayTimeSection();
        //初始化表格数据
        this._queryOperationRecordInfo();
    },
    methods: {
        /*----------------------------查询操作----------------------------*/
        //查询操作记录信息表格数据
        _queryOperationRecordInfo() {
            this.loading = true;
            queryOperationRecordInfo(this.formData)
                .then(res => {
                    this.loading = false;
                    this.tableData = res.content;
                    this.total = res.totalElements;
                })
                .catch(err => {
                    this.loading = false;
                    this.$message.error(err.message);
                });
        },
        //页码切换
        handleCurrentChange(val) {
            this.formData.pageNum = val;
            this._queryOperationRecordInfo();
        },
        //每页展示条数的切换
        handleSizeChange(val) {
            this.formData.pageSize = val;
            this._queryOperationRecordInfo();
        },
        //点击查询
        handleSearch() {
            this.formData.pageNum = 1;
            this.formData.pageSize = 10;
            this._queryOperationRecordInfo();
        },
        //点击清空
        handleClear() {
            this.formData = {
                userName: "",
                sources: "",
                moudleCode: "",
                remark: "",
                storeName: "",
                start: "",
                end: "",
                pageNum: 1,
                pageSize: 10
            };
            this.$message({
                type: "success",
                message: "清空成功!"
            });
            this.getTodayTimeSection();
            this._queryOperationRecordInfo();
        },

        /*----------------------------计算当天的开始时间和结束时间----------------------------*/
        getTodayTimeSection() {
            var datesection = this.UTILS.getTodayStartAndEndDate();
            this.formData.start = datesection.beginTime;
            this.formData.end = datesection.endTime;
        },

        /*----------------------------导出操作----------------------------*/
        handleExport() {
            this.UTILS.exportUtil(api.exportOperationRecordInfo, this.formData);
        }
    },
    components: {
        "m-pagination": mPagination
    }
};
</script>

<!-- Add "scoped" attribute to limit CSS to this component only -->
<style scoped>
</style>